﻿using System.Collections.Generic;
using System.Domain.Entity;
using System.Domain.IRepository;
using System.Repository.Base;
using System.Repository.DataBase.Models;
using Domain.Infrastructure;
using Microsoft.EntityFrameworkCore;

namespace System.Repository
{

   

    /// <summary>
    ///用户操作日志 接口 仓库实现 
    /// </summary>	
    public class SysOperationLogRepository : RepositoryDomain<SysOperationLogEntity, Sys_OperationLog>, ISysOperationLogRepository
    {
        public SysOperationLogRepository(IDbContextConfig config) : base(config)
        {
        }
        public override bool Update(SysOperationLogEntity entity)
        {
            Sys_OperationLog model = GetModel(entity.Id);
            if (model == null)
                return false;
            Dbcontext.Set<Sys_OperationLog>().Attach(model);
            Dbcontext.Entry(model).State = EntityState.Unchanged;
            AutoCopy(model, entity);
            return Dbcontext.SaveChanges() > 0;
        }

        public override bool Delete(string key)
        {
            return Delete(t => t.Id == key) > 0;
        }

        public List<SysOperationLogEntity> GetList(Pagination pagination, string userId, DateTime start, DateTime end)
        {
            var expression = ExtLinq.True<Sys_OperationLog>();
            expression = expression.And(t => t.CreatorTime >= start).And(t => t.CreatorTime <= end);
            if (!string.IsNullOrEmpty(userId))
                expression = expression.And(t => t.CreatorUserId == userId);
            return GetList(expression, pagination);
        }


    }

}
